<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<style>
			*{
				font-size:15px;
			}
			.box{
				position:relative;
			}
			input{
				border:0;
				outline: none;
			}
			table,td{
				border:2px solid #000;
			}
			table{
				border-collapse: collapse;
				}
			.right input{
				text-align: center;
				width:100px;
			}
			.inp11{
				width:20px;
				border:1px solid #000;
				text-align:center;
				position: absolute;
				left:-4px;
				margin:0 5px;
			}
			.box2{
				position:absolute;
				display: inline-block;
				width:25px;
				height:20px;
				left:138px;
				top:1px;
			}
		</style>
	</head>
	<body>
		
		<table>
			<tr>
				<td>书名</td>
				<td>价格</td>
			</tr>
			<tr>
				<td><input value="看得见风景的房间"></td>
				<td class="right"><input value="¥30.00"></td>
			</tr>
			<tr>
				<td><input value="幸福在哪里"></td>
				<td class="right"><input value="¥18.50"></td>
			</tr>
			<tr>
				<td><input value="60个瞬间"></td>
				<td class="right"><input value="¥32.00"></td>
			</tr>
		</table>
		<div class="box">
		<button>增加一行</button>
	    <button style="position:relative;">
	    	删除第&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;行
	    </button>
	    <div class="box2">
	    	<input type="text" value="2" id="inp1" class="inp11">
	    </div>
	   
		<button>修改标题样式</button>
		<button>复制最后一行</button>
		</div>
		<script>
//			获取节点
         var trs = document.getElementsByTagName("tr");
         console.log(trs);
         var btn = document.getElementsByTagName("button");
         var table = document.getElementsByTagName("table");
         var inp1 = document.getElementById("inp1");
          //console.log(inp1);
        //给增加一行添加点击事件
         btn[0].onclick = function(){
         	var tr1 = document.createElement("tr");
         	tr1.innerHTML="<td><input value='小王子'></td><td class='right'><input value='¥22.00'></td>";
            trs[0].parentNode.insertBefore(tr1,trs[2]);
//       	console.log(trs[0].parentNode);
         }
         //给删除第二行添加点击事件
//       var num = 0;//声明一个变量来存储点击按钮的次数
         btn[1].onclick = function(){
//       	num++;
//       	if(num%2==0){
         	   trs[0].parentNode.removeChild(trs[inp1.value]);
//         }
         	
         }
        //给修改样式添加点击事件
        btn[2].onclick = function(){
        	trs[0].style.background = "#ccc";
        	trs[0].style.fontWeight = "bold";
        	trs[0].style.textAlign = "center";
        }
        btn[3].onclick = function(){
        var a =	trs[trs.length-1].cloneNode(true);
        trs[0].parentNode.insertBefore(a,trs[trs.length-1]);
        }
		</script>
	</body>
</html>
